#ifndef __EKOS_LAYOUT_H__
#define __EKOS_LAYOUT_H__

/* This file defined the general layout of EKOS */

#define PIT_FREQ        100

#define IRQ_OFFSET      32      // IRQ 0 corresponds to int IRQ_OFFSET
#define IRQ_COUNT       32

#define IRQ_TIMER        0
#define IRQ_KBD          1
#define IRQ_SCTL         2
#define IRQ_IDE         14
#define IRQ_ERROR       19
#define IRQ_SPURIOUS    31

#define EX_PAGEFAULT 14
#define EX_SYS_KILL  32

#define RM_IMAGE_PAGES ((1 << 8) + (1 << 4))

/* EKOS is currently designed for supporting 256 cpus */
#define LAPIC_COUNT   256

/* The kernel stack size, including the 1 page boundary(temp page) */
#define KSTACK_SIZE  0x4000
#define KSTACK_SHIFT 14

/* Number of process */
#define PROCESS_MAX_COUNT 0x2000
#define PROCESS_MAX_COUNT_SHIFT 13

/* Number of IPS Node per process  */
#define PROCESS_IPS_COUNT 0x40
#define PROCESS_IPS_COUNT_SHIFT 6
/* IPS Reserved for system use */
#define PROCESS_IPS_RESERVED 4
#define PROCESS_IPS_EXCEPTION (PROCESS_IPS_COUNT - PROCESS_IPS_RESERVED)


#define WLEVEL_USER		0
#define WLEVEL_STIMER	0
#define WLEVEL_IPS		0
#define WLEVEL_START	8
#define WLEVEL_SYSTEM	16
#define WLEVEL_EXIT     24

/* Number of AP in the system */
#define IPS_AP_COUNT (1 << 14)

/* the 16M boundary for DMA memory */
#define DMA_BOUNDARY_PAGE (1 << 12)

#define GDT_COUNT 5 + LAPIC_COUNT
/* Global Descriptor */
#define GD_KERN_TEXT 0x08
#define GD_KERN_DATA 0x10
#define GD_USER_TEXT 0x18
#define GD_USER_DATA 0x20
#define GD_TSS(CPU) ((5 + CPU) << 3) 	/* Task segment selector */

/* Memory layout */

/* The address space of kernel */
#define KSTACK			0xf8000000
#define HPET            0xf0002000
#define LAPIC			0xf0001000
#define VPDLCK			0xf0000000
#define	KBASE			0xf0000000
#define KISIZE			0x08000000
#define KSIZE			0x10000000
/* The 4M page table mirror address */
#define KVPT			0xefc00000
/* The user access limit */
#define ULIM			0xefc00000
/* Same as VPT but read-only for users */
#define UVPT			0xef800000
/* The read-only info for system configuration */
#define USYSCONF        0xef7ff000
/* The read-only for local apic */
#define ULAPIC          0xef7fe000
/* The read-only for task seg of each cpu */
#define UTASK           0xef700000
/* irq queue struct, the ctrl block is read only for user, other part
 * is forbidden for user */
#define UIRQ_PIPE       0xef600000
/* Proc struct, read only for users */
#define UPROCS          0xef400000
/* The user write limit */
#define UWLIM			0xef400000
/* EKOS user core lib */
#define ULIB			0x00000000
#define ULIB_SIZE		0x04000000
/* There a problem arises, since we use NULL pointer(0) to indicate a
 * meanless hole and to detect error, so the first page should not be
 * mapped. */

#endif
